a11y: Set accessible roles for GtkImage and GtkPicture
authorMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 19:44:12 +0000 (15:44 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 22:16:37 +0000 (18:16 -0400)
Use the img accessible role for these.
Also update the documentation and add tests.

docs/reference/gtk/section-accessibility.md
gtk/gtkenums.h
gtk/gtkimage.c
gtk/gtkpicture.c
testsuite/a11y/image.c [new file with mode: 0644]
testsuite/a11y/meson.build

index f640c962b0c943055d55e954244c4d339dc8d4f3..b8879731d303e9f00a9a22512d2816c13731bdde 100644 (file)
@@ -51,6 +51,7 @@ Each role name is part of the #GtkAccessibleRole enumeration.
 | `COLUMNHEADER` | The header of a column in a list or grid | - |
 | `COMBOBOX` | A control that can be expanded to show a list of possible values to select | #GtkComboBox |
 | `DIALOG` | A dialog that prompts the user to enter information or require a response | #GtkDialog and subclasses |
+| `IMG` | An image | #GtkImage, #GtkPicture |
 | `PROGRESS_BAR` | An element that display progress | #GtkProgressBar |
 | `RADIO` | A checkable input in a group of radio roles | #GtkRadioButton |
 | `SCROLLBAR` | A graphical object controlling the scolling of content | #GtkScrollbar |
index 436d2ac39d4cba82a79d08142b19b9f8cf1a07e1..3d3b72b71c5c909c706b7db1a61705c247fe36bd 100644 (file)
@@ -1181,7 +1181,7 @@ typedef enum {
  * @GTK_ACCESSIBLE_ROLE_GRID_CELL: Unused
  * @GTK_ACCESSIBLE_ROLE_GROUP: Unused
  * @GTK_ACCESSIBLE_ROLE_HEADING: Unused
- * @GTK_ACCESSIBLE_ROLE_IMG: Unused
+ * @GTK_ACCESSIBLE_ROLE_IMG: An image.
  * @GTK_ACCESSIBLE_ROLE_INPUT: Unused
  * @GTK_ACCESSIBLE_ROLE_LABEL: Unused
  * @GTK_ACCESSIBLE_ROLE_LANDMARK: Unused
index e03cc45f067812df8d4944e13463cdbc3b5022a1..4e0b5930f5f3896635b2b7451ff34e6873c451c0 100644 (file)
  * GtkImage has a single CSS node with the name image. The style classes
  * .normal-icons or .large-icons may appear, depending on the #GtkImage:icon-size
  * property.
+ *
+ * # Accessibility
+ *
+ * GtkImage uses the #GTK_ACCESSIBLE_ROLE_IMG role.
  */
 
 typedef struct _GtkImageClass GtkImageClass;
@@ -261,6 +265,8 @@ gtk_image_class_init (GtkImageClass *class)
   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, image_props);
 
   gtk_widget_class_set_css_name (widget_class, I_("image"));
+
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_IMG);
 }
 
 static void
index 4ac96751757631aea3acb67a13021d6d42d9989d..9c2b87c9e74ec8558ef45fee8797dbbc2691249a 100644 (file)
  * # CSS nodes
  *
  * GtkPicture has a single CSS node with the name picture.
+ *
+ * # Accessibility
+ *
+ * GtkImage uses the #GTK_ACCESSIBLE_ROLE_IMG role.
  */
 
 enum
@@ -365,6 +369,7 @@ gtk_picture_class_init (GtkPictureClass *class)
   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
 
   gtk_widget_class_set_css_name (widget_class, I_("picture"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_IMG);
 }
 
 static void
diff --git a/testsuite/a11y/image.c b/testsuite/a11y/image.c
new file mode 100644 (file)
index 0000000..e7c4897
--- /dev/null
@@ -0,0 +1,34 @@
+#include <gtk/gtk.h>
+
+static void
+image_role (void)
+{
+  GtkWidget *widget = gtk_image_new ();
+  g_object_ref_sink (widget);
+
+  gtk_test_accessible_assert_role (widget, GTK_ACCESSIBLE_ROLE_IMG);
+
+  g_object_unref (widget);
+}
+
+static void
+picture_role (void)
+{
+  GtkWidget *widget = gtk_picture_new ();
+  g_object_ref_sink (widget);
+
+  gtk_test_accessible_assert_role (widget, GTK_ACCESSIBLE_ROLE_IMG);
+
+  g_object_unref (widget);
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/a11y/image/role", image_role);
+  g_test_add_func ("/a11y/picture/role", picture_role);
+
+  return g_test_run ();
+}
index 0b672a3e4e111807040947088f33e5444742ae9e..e56f145c82698ca2273ecd253df172e379e2eb0d 100644 (file)
@@ -14,6 +14,7 @@ tests = [
   { 'name': 'button' },
   { 'name': 'checkbutton' },
   { 'name': 'dialog' },
+  { 'name': 'image' },
   { 'name': 'progressbar' },
   { 'name': 'scrollbar' },
   { 'name': 'separator' },